<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/views/includes.jsp" %>
<%@page import="java.util.Set"%><%@page import="java.util.Map"%>
<%@ page import="com.cheapflix.beans.DVD" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Welcome to Cheapflix</title>
        <link rel="stylesheet" type="text/css" href="/cheapflix/css/style.css" />
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/login.js"/>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    </head>
    <body>
        <div class="outer">
            <%@ include file="/WEB-INF/views/header.jsp" %>
            <div class="row rowstyle rowleft">
                <div style="margin:25px"><h3>Welcome <c:out value="${me.nameFirst}"/> <c:out value="${me.nameLast}"/>!</h3></div>
                <table>
                    <tr>
                        <td>
                            <span class="message">Movies recommended to me</span>
                            <div style="width:300px" class="searchResults">

                                <% int i = 0;
                                    Set<DVD> dvds = (Set<DVD>) request.getAttribute("movies");
                                %>
                                <c:forEach items="${movies}" var="movie">
                                    <%
                                        DVD movie = (DVD) pageContext.getAttribute("movie");
                                        Map< String, Integer> recommendationTimes = (Map< String, Integer>) request.getAttribute("recommendationTimes");
                                        int numtimes = recommendationTimes.get(movie.getId() + "");
                                        String cssClass = "";

                                        if (i < dvds.size() - 1) {
                                            cssClass = "SingleResult";
                                        }
                                    %>
                                    <div class="<%=cssClass%>">
                                        <a href="/cheapflix/searchId?id=<c:out value="${movie.id}"/>"><c:out value="${movie.title}"/> - <c:out value="${movie.year}"/></a> (<a href="/cheapflix/recommenddetails?dvdid=<c:out value="${movie.id}"/>"><%= numtimes%></a>)
                                    </div>
                                    <% i++;%>
                                </c:forEach>
                            </div>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${fn:length(me.friends) > 0}">
                                    <span class="message">My FlickFriends</span>
                                    <div style="width:300px" class="searchResults">
                                        <table class="stdTable">
                                            <c:forEach items="${me.friends}" var="friend">
                                                <tr>
                                                    <td><a href="/cheapflix/users/<c:out value="${friend.value.id}"/>"><c:out value="${friend.value.nameFirst}"/> <c:out value="${friend.value.nameLast}"/></a></td>
                                                </tr>
                                            </c:forEach>
                                        </table>
                                    </div>
                                    </c:when>
                                    <c:when test="${fn:length(me.friends) == 0}">
                                        <span class="message">You have no FlickFriends</span>
                                        <div style="width:300px" class="searchResults">

                                        </c:when>
                                    </c:choose>
                                    <div style="margin-top:10px;">
                                        Search For Users:
                                        <form action="/cheapflix/usersearch" method="GET" style="margin-bottom:20px;" >
                                            <input type="text" name="q" value='<c:out value="${param.q}"/>'/>
                                            <input type="submit" value="Search"/>
                                        </form>
                                    </div>
                                </div>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${fn:length(me.userDVDs) > 0}">
                                    <span class="message">Flick Queue Quick View</span><br/>
                                    <div style="margin-top:20px"><a href="/cheapflix/UserQueue/<c:out value="${me.id}"/>">Full View</a></div>
                                    <div class="searchResults">
                                        <table class="stdTable">
                                            <c:forEach items="${me.userDVDs}" var="userDVDEntry">
                                                <tr>
                                                    <td>
                                                        <c:choose>
                                                            <c:when test="${userDVDEntry.value.rating!=0}">
                                                                <img src="<c:url value="/images/accepted.png"/>"/>
                                                            </c:when>
                                                        </c:choose>
                                                    </td>
                                                    <td><a href="/cheapflix/searchId?id=<c:out value="${userDVDEntry.value.dvd.id}"/>"><c:out value="${userDVDEntry.value.dvd.title}"/></a></td></tr>
                                                </c:forEach>
                                        </table>
                                    </div>
                                </c:when>
                                <c:otherwise>
                                    <span class="message">No Items in your Flick Queue</span>
                                </c:otherwise>
                            </c:choose>
                        </td>
                    </tr>
                </table>

            </div>
            <%@ include file="/WEB-INF/views/footer.jsp" %>
        </div>

    </body>
</html>